<template>
  <div class="content-card">
    <div class="title">
      <a-icon type="tags"></a-icon>
      <span>{{ "开放数据总览" }}</span>
    </div>
    <div class="body">
      <div class="child-item">
        <span class="label">{{ "部门数" }}</span>
        <div class="value">
          <img src="@/assets/img/develop/1-1.jpg" alt="1-1" />
          <span>{{ deptNum }}</span>
        </div>
      </div>
      <div class="child-item">
        <span class="label">{{ "开放目录数" }}</span>
        <div class="value">
          <img src="@/assets/img/develop/1-2.jpg" alt="1-2" />
          <span>{{ openDirNum }}</span>
        </div>
      </div>
      <div class="child-item">
        <span class="label">{{ "开放数量总量" }}</span>
        <div class="value">
          <img src="@/assets/img/develop/1-3.jpg" alt="1-3" />
          <span>{{ openSumNum }}</span>
        </div>
      </div>
      <div class="child-item">
        <span class="label">{{ "数据应用数量" }}</span>
        <div class="value">
          <img src="@/assets/img/develop/1-4.jpg" alt="1-4" />
          <span>{{ dataAppNum }}</span>
        </div>
      </div>
      <div class="child-item">
        <span class="label">{{ "开放网站访问量" }}</span>
        <div class="value">
          <img src="@/assets/img/develop/1-5.jpg" alt="1-5" />
          <span>{{ openNetNum }}</span>
        </div>
      </div>
      <div class="child-item">
        <span class="label">{{ "数据下载数量" }}</span>
        <div class="value">
          <img src="@/assets/img/develop/1-6.jpg" alt="1-6" />
          <span>{{ dataDownNum }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import API from "@/api/develop";
export default {
  name: "d1-card",
  data() {
    return {
      deptNum: 0,
      openDirNum: 0,
      openSumNum: 0,
      dataAppNum: 0,
      openNetNum: 0,
      dataDownNum: 0,
    };
  },
  methods: {
    getBoxData() {
      let handleV1 = (res) => (this.deptNum = res.data.body.data[0].deptment);
      let handleV2 = (res) => (this.openDirNum = res.data.body.data[0].kfmls);
      let handleV3 = (res) => (this.openSumNum = res.data.body.data[0].kfslzl);
      let handleV4 = (res) => (this.dataAppNum = res.data.body.data[0].sjyysl);
      let handleV5 = (res) => (this.openNetNum = res.data.body.data[0].kfwzfwl,console.log(res.data.body.data[0]));
      let handleV6 = (res) => (this.dataDownNum = res.data.body.data[0].sjxzsl);

      API.getdeptment().then(handleV1);
      API.getopenDirNum().then(handleV2);
      API.getopenSumNum().then(handleV3);
      API.getdataAppNum().then(handleV4);
      API.getkfwzfwl().then(handleV5);
      API.getsjxzsl().then(handleV6);
    },
    getTask() {
      return () => {
        this.getBoxData();
      };
    },
  },
  mounted() {
    this.getTask()(); // 先执行 一次任务
    this.timer = setInterval(this.getTask(), 30000); // 设置周期触发任务
  },
  beforeDestroy() {
    clearInterval(this.timer);
    this.timer = null;
  },
};
</script>

<style lang="less" scoped>
.content-card {
  .title {
    display: flex;
    align-items: center;
    padding: 10px 0;
    background: linear-gradient(to right, #dee9ff, #ffffff);
    i {
      color: #6989c6;
      margin: 0 15px;
      font-size: 18px;
    }
    span {
      font-size: 16px;
      font-weight: 500;
    }
  }
  .body {
    width: 100%;
    height: 220px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    padding: 10px 5px;
    .child-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      font-size: 16px;
      .label {
        font-size: 14px;
        color: #666;
        margin-bottom: 10px;
      }
      .value {
        display: flex;
        justify-content: center;
        font-size: 16px;
        img {
          margin-right: 6px;
          width: 24px;
          height: 24px;
        }
        span {
          font-size: 20px;
          font-weight: 500;
        }
      }
      &:nth-child(1) {
        border-right: 1px solid #eee;
        border-bottom: 1px solid #eee;
        .value span {
          color: #00df91;
          &::after {
            content: "个";
            font-size: 14px;
          }
        }
      }
      &:nth-child(2) {
        border-right: 1px solid #eee;
        border-bottom: 1px solid #eee;
        .value span {
          color: #faae62;
          &::after {
            content: "个";
            font-size: 14px;
          }
        }
      }
      &:nth-child(3) {
        border-bottom: 1px solid #eee;
        .value span {
          color: #3695ff;
          &::after {
            content: "个";
            font-size: 14px;
          }
        }
      }
      &:nth-child(4) {
        border-right: 1px solid #eee;
        .value span {
          color: #00df91;
          &::after {
            content: "个";
            font-size: 14px;
          }
        }
      }
      &:nth-child(5) {
        border-right: 1px solid #eee;
        .value span {
          color: #faae62;
          &::after {
            content: "次";
            font-size: 14px;
          }
        }
      }
      &:nth-child(6) {
        .value span {
          color: #3695ff;
          &::after {
            content: "个";
            font-size: 14px;
          }
        }
      }
    }
  }
}
</style>
